/*
 * @Author: Lijin
 * @Date: 2024-09-19 13:56:33
 * @LastEditors: Lijin
 * @LastEditTime: 2024-09-23 10:12:46
 * @FilePath: \huawei-flash-sale\join.js
 * @Description:
 *
 * Copyright (c) 2024 by 18323406700, All Rights Reserved.
 */
const axios = require("axios");
const moment = require("moment");

const activityID = 249933;

const orders = [
  2601010506011, 2601010506009, 2601010506010, 2601010506012, 2601010506019,
  2601010506020,
];

const Cookie =
  "deviceid=66587e712df0c2488b294802c37aff29; TID=66587e712df0c2488b294802c37aff29; selectShopId=104352738; euid=186a09096501abdc0500da0d9e9960b3b2dec0070936d26e; CSRF-TOKEN=CF7987AF0EC0074EE515EDEF83A5627527F6113F0D22BF39B96E6924E06EE596; hasSigned=0; isFirstLogin=0; aliToken=; isGroupUser=false; ageGroupFlag=-1; optBanding=0; weChatInfo=false; ac_loNa=183****6700; ac_lel=; ac_lmi=; ac_lus=1; ac_lgc=0; ac_ltp=0; ac_li=true; isVpro=0; ac_cp=1500721829297|1500721912154|1599634375481; rush_info=220086000133010848_1727055628_SEC1A094D2FE477DB7986EBE648560A63D78359855E9B8E34C2E201E82A1AD10DF7; rush_ext=220086000133010848_1_0_1727055628_SECE10D4B5CFD28EF0AB340BD22BE73644BBBDBD286FA7948368FE66DEAECB3CBE7; uid=220086000133010848; user=183****6700; hasphone=1; displayName=%E5%AE%9D****; grouptags=101805|99211|99193|99224; sdevid=39489999ddc997ebdb343d45734565c10c919803; HWWAFSESID=5f79e8bdf46c215aa1; HWWAFSESTIME=1727055628858; callAB=1; isAuthCust=false; isAuthByUid=true; recommendflag=true; device_data=*2k94MMPgMcdjTjzWG0CjDDmPgPkMZOZLIZ4JUMUaY4z1zm2mFlHLylXyTwTxBFQ0cINAU40MEm5mz3MbNNOMAcYZFVYzz32p395k502wXzNuThhw4kilNNMNMOAYZZVQONQoMNBFNYVxNVEUNR4xMMgY2Dhyj2k1Wm9hmTpljjsyFWlwjmyxn3yzDzwxT7PMJMMYNdNYZTbMMNSMMJJMOMMTmmm2zwzG12YPaIAMMdUMO9pDDTTXjSCmTW3CCjykmjTDmj2lgYNgAMNQUOZBQcMZZZMgAYcp4MLUkdNUBbMkT4yTTm5zT562jwvjWlliCHDCWmmDzm1Tn35GWcKI0UYZJwEVYZ1B4UUUZd0IdYZ3y2Dm1Dm0vDNBMOcQMYlIZWE43ix94l9lmshlyppv1mo90wjPcgZMFVZMIUNZJZNN5NNM5xcbIMMNBtMQNJLckySHy4TjwwWmNG3D22kyylHjhunnxwWDl3mTfGVNYYMcMOdYMabdQYMaMbJaPZa2Dmz52D4wm2PUMdMZEJOIIMTGjWT2TmCTzWSmCVjjzWDCmWmCMMIadIQMYNUMMYANcMJNY9UbKRIacdhTbBAYjGGllTT05DS9pTjyzHCzy2WxlzVywTj2sDz2iuYREFQBIdQ1g4JdgBUkcREkIkBTjwmTj55jCpdNMQNVxumj0hwBrl9imMJPIXUZcYYTFbBZRMBj9HlGuGOiyGlkpnwTyJZYNMbJJMZbcME5n4zkY3Rd";

const init = () => {
  for (let i = 0; i < orders.length; i++) {
    axios({
      method: "get",
      url: `https://buy.vmall.com/joinQueue.json?activityID=${activityID}&sbomCode=${orders[i]}&num=1&portal=1`,
      headers: {
        Accept: "application/json",
        "Accept-Encoding": "gzip, deflate, br, zstd",
        "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
        "Cache-Control": "no-store",
        Connection: "keep-alive",
        Cookie: Cookie,
        Origin: "https://www.vmall.com",
        Pragma: "no-cache",
        Referer: "https://www.vmall.com/",
        "Sec-Fetch-Dest": "empty",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Site": "same-site",
        "User-Agent":
          "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36",
        "X-E2E-Trace":
          "e2eId=page#rn_product#1#02b6151906d4e9fba7840a939bdaa876;spanId=d259261f6f8d3230a5df626b3aa0ee47",
        "sec-ch-ua":
          '"Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128"',
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": '"Windows"',
      },
    })
      .then((res) => {
        //返回的数据乱码
        // console.log(res);
        console.log(`当前id:${orders[i]}`, JSON.stringify(res.data));

        console.log("----------------------- 当前时间戳", new Date().getTime());

        setInterval(() => {
          axios({
            method: "get",
            url: `
            https://buy.vmall.com/queryQualification.json?activityID=${activityID}&sbomCode=${
              orders[i]
            }&portal=1&rushTimestamp=${
              // res.data.data.rp
              11
            }&t=${new Date().getTime()}`,
            headers: {
              Accept: "application/json",
              "Accept-Encoding": "gzip, deflate, br, zstd",
              "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
              "Cache-Control": "no-store",
              Connection: "keep-alive",
              Cookie: Cookie,
            },
          }).then((res1) => {
            console.log(JSON.stringify(res1.data));
            if (res1.data.success) {
              console.log(
                "拿下！！！！！！！！！！！！！！！！！！！！！！！！！！！！"
              );
            }
          });
        }, 3000);
        // if (res.data.success) {
        //   clearInterval(timer);
        // }

        // debugger;
      })
      .catch((er) => {
        console.log(er);
      });
  }
};

let t = "2024-09-23 10:08:00"; //开始时间
let times = new Date(t).getTime();
console.log("目标时间戳", times);

/**
 *  2022-06-19T04:03:50.378Z  -500
    2022-06-19T04:05:50.743Z  -200
    2022-06-19T04:09:50.891Z  -100
    2022-06-19T04:07:11.282Z  
 
 */
let js = setInterval(() => {
  if (new Date().getTime() >= times - 300) {
    clearInterval(js);
    console.log("开始执行");
    console.log(new Date().getTime());
    init();
  }

  console.log(
    `目标时间:${t},当前时间${moment(new Date().getTime()).format(
      "YYYY-MM-DD HH:mm:ss"
    )}`
  );
}, 100);
